package com.my.chapter13;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class practice10 {
    public static void main(String[] args) {
        String[] str = {"Java now has regular expressions","^Java","\\Breg.*","n.w\\s+h(a|i)s","s?",
                        "s*","s+","s{4}","s{1}.","s{0,3}"};
        for(String s:str){
            System.out.println("Regular expression：\"" + s + "\"");
            Pattern p = Pattern.compile(s);
            Matcher m = p.matcher(str[0]);
            while(m.find()){
                System.out.println("Match \"" + m.group() + "\" at positions " + m.start() + "-" + (m.end()-1));
            }
        }
    }
}
